package com.sphd.beautysalon.model;


import com.android.volley.VolleyError;
import com.sphd.beautysalon.presenter.GetIntegralPresenterImpl;
import com.sphd.beautysalon.info.JiFenInfo;
import com.sphd.beautysalon.interfaces.VolleyJsonObjectCallBack;
import com.wzh.frame.utils.JsonUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
* Created by Hu on 2016/11/14
*/

public class GetIntegralModelImpl implements GetIntegralModel, VolleyJsonObjectCallBack {
    GetIntegralPresenterImpl getIntegralPresenter;

    @Override
    public void sendUrl(String url, GetIntegralPresenterImpl getIntegralPresenter) {
            this.getIntegralPresenter=getIntegralPresenter;
        volleyUtil.setJsonObjectRequest(url,this);
    }

    @Override
    public void onResponse(JSONObject response) {
        try {
            List<JiFenInfo> jiFenInfoList = JsonUtil.getListFromString(response.getString("list"),JiFenInfo.class);
            int integral =response.getInt("integral");
            getIntegralPresenter.sendRes(jiFenInfoList,integral);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onErrorResponse(VolleyError error) {
        getIntegralPresenter.sendError(error);
    }
}